local canshi = fk.CreateSkill {
  name = "lingling__canshi",
}

Fk:loadTranslationTable{
  ["lingling__canshi"] = "蚕食",
  [":lingling__canshi"] = "出牌阶段，你可以弃置一张红色基本牌，令一名其他角色交给你一张牌，然后若为第偶数次发动，目标摸X张牌并失去1点体力"..
  "（X为其本回合因此失去体力次数）。",

  ["#lingling__canshi"] = "蚕食：弃一张红色基本牌，令一名角色交给你一张牌",
  ["#lingling__canshi2"] = "蚕食：弃一张红色基本牌，令一名角色交给你一张牌，其摸牌并失去体力",
  ["#lingling__canshi-give"] = "蚕食：请交给 %src 一张牌",
}

canshi:addEffect("active", {
  anim_type = "offensive",
  prompt = function (self, player)
    if player:usedSkillTimes(canshi.name, Player.HistoryPhase) % 2 == 0 then
      return "#lingling__canshi"
    else
      return "#lingling__canshi2"
    end
  end,
  card_num = 1,
  target_num = 1,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and not player:prohibitDiscard(to_select) and
      Fk:getCardById(to_select).type == Card.TypeBasic and Fk:getCardById(to_select).color == Card.Red
  end,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and not to_select:isNude()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:throwCard(effect.cards, canshi.name, player, player)
    if player.dead or target.dead then return end
    if not target:isNude() then
      local card = room:askToCards(target, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = canshi.name,
        prompt = "#lingling__canshi-give:"..player.id,
        cancelable = false,
      })
      room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, canshi.name, nil, false, target)
    end
    if player:usedSkillTimes(canshi.name, Player.HistoryPhase) % 2 == 0 and not target.dead then
      room:addPlayerMark(target, "lingling__canshi-turn", 1)
      target:drawCards(target:getMark("lingling__canshi-turn"), canshi.name)
      if not target.dead then
        room:loseHp(target, 1, canshi.name)
      end
    end
  end,
})

return canshi
